﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Easydp.Models.Entities;
using Easydp.Models;
using System.Data;
namespace Easydp.Controllers
{
   [DataObject()]
   public class AgentController
    {
       AgentManager agentManager = new AgentManager();
        

       private static TT_Agent agentInfo;
       public static TT_Agent AgentInfo
       {
           set { agentInfo = value; }
           get { return agentInfo; }
       }

       public void InitAgentInfo(string loginName)
       {
           agentInfo = agentManager.GetByLoginName(loginName);
       }

       [DataObjectMethod(DataObjectMethodType.Select)]
       public TT_Agent GetByLoginName(string loginame)
       {
           return agentManager.GetByLoginName(loginame);
       }
       [DataObjectMethod(DataObjectMethodType.Update)]
       public void Update(TT_Agent obj)
       {
           try
           {
              int i = agentManager.Update(obj);
              if (i <= 0)
                  throw new Exception("更新失败");
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message);
           }
       }
       /// <summary>
       /// 获得数据列表
       /// </summary>
       /// 
       [DataObjectMethod(DataObjectMethodType.Select)]
       public DataSet GetDataset(string strWhere)
       {
           return agentManager.GetDataset(strWhere);
       }

       /// <summary>
       /// 得到列表
       /// </summary>
       /// 
       [DataObjectMethod(DataObjectMethodType.Select)]
       public List<TT_Agent> Getlist(int AgentID)
       {
           return agentManager.GetList(AgentID);
       }

       [DataObjectMethod(DataObjectMethodType.Select)]
       public List<TT_Agent> GetListByCity(string city)
       {
           return agentManager.GetListByCity(city);
       }
        [DataObjectMethod(DataObjectMethodType.Select)]
       public DataSet GetListByArea(string area)
       {
           return agentManager.GetListByArea(area);
       }
       
       public List<string> GetAllCity()
       {
          List<string> res =agentManager.GetAllCity();
                res.Insert(0, "不限");
          return res;
       }
        //AgentManager agentManager;
        //public AgentController()
        //{
        //    agentManager = new AgentManager();
        //}

        //public TT_Agent Get(string loginName)
        //{
        //    return agentManager.Get(loginName);
        //}
       [DataObjectMethod(DataObjectMethodType.Insert)]
       public void Insert(TT_Agent obj)
       {
           try
           {
               agentManager.Insert(obj);
           }
           catch (Exception e)
           {
               throw new Exception(e.Message);
           }
       }
    }
}
